Promise.any = promises =>{
	return new Promise((resolveAll, rejectAll)=>{
		let reasons = []
		let counter = 0;
		promises.forEach(defineAction);
		function defineAction(promise, i){
			promise.then(onResolved, onRejected);
			function onResolved(value){
				resolveAll(value)
				return Promise.resolve(value);
			}
			function onRejected(reason){
				reasons[i] = reason;
				counter++;
				if(counter === promises.length) rejectAll(reasons);
				return Promise.reject(reason)
			}
		}
	})
}

let promises = [
    new Promise((resolve, reject)=>setTimeout(_=>reject('失败'), 1000)),
    new Promise((resolve, reject)=>setTimeout(_=>reject('失败'), 1000)),
    new Promise((resolve, reject)=>setTimeout(_=>reject('失败'), 1000)),
    new Promise((resolve, reject)=>setTimeout(_=>reject('失败'), 1000)),
    new Promise(resolve=>setTimeout(_=>resolve('成功1'), 1000)),
    new Promise(resolve=>setTimeout(_=>resolve('成功2'), 1000)),
    new Promise(resolve=>setTimeout(_=>resolve('成功3'), 1000)),
    new Promise((resolve, reject)=>setTimeout(_=>reject('失败'), 1000)),
]

try{
    console.log(await Promise.any(promises))
}catch(e){
    console.log(e)
}

/*
 * 我没法测试
:!node wtf.mjs
node:internal/process/promises:279
            triggerUncaughtException(err, true
 */